Skip to content

Conversation

@00xc
Copy link
Contributor

@00xc 00xc commented Oct 2, 2023

If a user provides a layout with a big enough size, the allocator might panic on an unwrap instead of returning an error. The reason is that, even though the layout size is properly rounded to a power of two, Layout::from_size_align() will fail if the size overflows isize when rounded to the layout alignment.

Fix this by handling the error instead of unwrapping it.

Keep an unwrap in the HoleList::deallocate() as the validity of the layout must be guaranteed by the caller since it is an unsafe function.

If a user provides a layout with a big enough size, the allocator
might panic on an unwrap instead of returning an error. The reason is
that, even though the layout size is properly rounded to a power of
two, Layout::from_size_align() will fail if the size overflows isize
when rounded to the layout alignment.

Fix this by handling the error instead of unwrapping it.

Keep an unwrap in the HoleList::deallocate() as the validity of the
layout must be guaranteed by the caller since it is an unsafe
function.
Copy link
Member

@phil-opp phil-opp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@phil-opp phil-opp enabled auto-merge October 25, 2023 12:55
@phil-opp phil-opp merged commit 3c9bafa into rust-osdev:main Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants